package com.bgybmi.sms;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.bgy.model.Meetingcreate;
import com.bgybmi.config.ConfigEnum;
import com.bgybmi.entity.MeetCreate;
import com.bgybmi.thread.SendMsg;
import com.jfinal.kit.PropKit;

/**
 * 定时设置会议状态，如果会议已经结束，设置成  1 结束
 * @author Administrator
 *
 */
public class TimerSendFlag {
	
	public TimerSendFlag(){		
		new Thread(new Runnable(){
			@Override
			public void run() {
				int time_delay = 3000;				
				while(true){
					try {
						Thread.sleep(time_delay);
						//1.会议问题
						timerSend();
						//timerSetStatus();						
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}


		}).start();
	}
	private void timerSend() {
		// TODO Auto-generated method stub
		List<MeetCreate> sendList=MeetCreate.me.getSendList();
        for (MeetCreate mc : sendList) {
			String chr=mc.get("chr");
			String starttime=mc.get("starttime")+"";
			String url=SmsUrl.Meet.getName();
			String msg="您有新的会议将于"+starttime+"开始,<a href=\""+url+"\">查看</a>";
			SendMsg sm=new SendMsg(chr.replace(",","|"),msg,ConfigEnum.HY.getAgentId());
			sm.start();	
			setStatus(mc);
		}       
	}
	
	private void setStatus(MeetCreate mc) {
		// TODO Auto-generated method stub
		mc.set("sendflag", 1);
		mc.update();
	}

	private void timerSetStatus(){
		Meetingcreate.me.setStatus();
	}
}
